package com.hzya.frame.mdm.mdmModule;

import com.alibaba.excel.EasyExcel;
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
import com.hzya.frame.mdm.mdmModule.vo.ExcelTemplateVO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;


public class WriteTest {

    @Autowired
    private IMdmModuleService mdmModuleService;

    @Test
    public void testGenerateExcelTemplate() throws IOException {
        // 文件夹路径
        String folderPath = "D:/test/";
        // 完整文件路径（文件夹 + 文件名）
        String localFilePath = folderPath + "表字段定义模版.xlsx";
        File dir = new File(folderPath);
        if (!dir.exists()) {
            dir.mkdirs(); // 创建文件夹（如果不存在）
        }
        // 准备模板的示例数据
        List<ExcelTemplateVO> demoData = new ArrayList<>();
        // 生成Excel并保存到本地文件
        try (OutputStream outputStream = new FileOutputStream(localFilePath)) {
            EasyExcel.write(outputStream, ExcelTemplateVO.class)
                    .sheet("表字段定义模版")
                    .doWrite(demoData);
        }
        System.out.println("Excel模板已成功生成，保存路径：" + localFilePath);
    }



}
